<template>
  <div class="update-gender">
      <van-picker
        title="选择性别"
        show-toolbar
        :columns="columns"
        @confirm="onSubmit"
        @cancel="$emit('close')"
        :default-index="value"
        />
  </div>
</template>
<script>
import { updateUserInfo } from "@/api/user";
export default {
    name:"UpdateGender",
    props:{
        value:{
            type:[String,Number],
            required:true
        }
    },
    data(){
        return{
            columns:['男','女']
        }
    },
    created(){},
    methods:{
        // 修改资料
        async onSubmit(val,idx){
          this.$toast.loading({
        message:'更新中',
        duration:0
      })
             try {
              const { data:res } = await updateUserInfo({
                gender:idx
              })
              this.$toast.success('更新成功')
              this.$emit('input',idx)
              this.$emit('close')
              console.log(idx);
            } catch (error) {
              this.$toast.fail('更新失败')
              
            }
        }
    },
    components:{}
}
</script>
<style scoped lang="less">
.field-wrap{
    margin:30px;
    /deep/ .van-field__control{
        padding: 14px;
    }
}
</style>